import axios from 'axios';
import { ElMessage } from 'element-plus'
const API_BASE_URL = '/collectApi'; // 根据实际情况设置基础URL
 
const apiClient = axios.create({
  baseURL: API_BASE_URL,
  // 其他axios配置选项
//   timeout:10000
});

const CollectApi = {

//前端读取Excel文件后向采集发送频点等数据
    async postAllData(collectData){
        try {
            const response = await apiClient.post('/postExcelData',{"collectConfig":collectData},{
                headers: {
                'Content-Type': 'application/json'
                }
            })
            return response
        }catch(error) {
            console.log("向采集发送配置失败，错误码"+error.response.status+",检查服务端是否开启")
            ElMessage.error("向采集发送配置失败，错误码"+error.response.status+",检查服务端是否开启")
        }
    },
    async postStop(stopData){
        try {
            const response = await apiClient.post('/stop',stopData,{
                headers: {
                'Content-Type': 'application/json'
                }
            })
            return response.data
        }catch(error) {
            ElMessage.error("停止该路采集失败，检查服务端是否开启")
        }
    },
    async stopAll(){
        try {
            const response = await apiClient.post('/stopAll',{"stopAll":true},{
                headers: {
                'Content-Type': 'application/json'
                }
            })
            return response.data
        }catch(error) {
            ElMessage.error("停止所有采集通路失败，检查服务端是否开启")
        }
    },
    async postModify(modifyData){
        try {
            const response = await apiClient.post('/modify',modifyData,{
                    headers: {
                    'Content-Type': 'application/json'
                    }
                })
            return response.data
        }catch(error) {
            ElMessage.error("修改频点、增益失败，检查服务端是否开启")
        }
    },
    async getCollectConfig(){
        try {
            const response = await apiClient.get('/collectConfig')
            return response.data
        }catch(error) {
            ElMessage.error("获取当前所有采集配置失败，检查服务端是否开启")
        }
    }
}

export default CollectApi